<template>
	<view class="">
		<view class="">
			<navgetbar title="关注店铺"></navgetbar>
		</view>
		<view class="nologin">
			<view class="radius-[50%] w-[220rpx] h-[220rpx]">
				<up-image :show-loading="true" shape="circle" :src="headtals.doorstepPhoto"  width="220rpx"
					height="220rpx" class="buliselimg"></up-image>
			</view>
			<view class="nologinmsg">
				{{headtals.name}}
			</view>
			<view class="">
				<button  class="onejianlogin" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
					boder="none">关注店铺</button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import navgetbar from "@/components/navgetbar/navindex.vue"
	import {
		ref,reactive
	} from 'vue';
	const scene = ref("")
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		storenamedetal,
		storecollect,
		storeconcern,
		storestores,
		loginin
	} from "@/api/home.js"
	const headtals = reactive({

	})
	const islogin=ref(false)
	onLoad((query) => {
		// scene.value = decodeURIComponent(query.scene)
		// let parmslist = scene.value.split("+")
		// if (parmslist.length > 1) {
			// scene.value = parmslist[1]
			// console.log(parmslist[1])
			storenamedetal({
				storeId: query.id,
			}).then(res => {
				if (res.code == 200) {
					Object.assign(headtals, res.result)
				}
			})
		// }
		if (uni.getStorageSync('loginTokenKey') !== '' || uni.getStorageSync('loginTokenKey') !== null) {
			islogin.value = true
		} else {
			islogin.value = false 
		}
	})

	const getPhoneNumber = (res) => { 
		if (res.detail.code) {
			uni.login({
				"provider": "weixin",
				"onlyAuthorize": true, // 微信登录仅请求授权认证
				success: function(event) {
					const {
						code
					} = event
					loginin({
						phone: "",
						code: code,
						telCode: "",
						wtelCode: res.detail.code,
						loginType: 1,
						isAgreement: true
					}).then(res => {
						console.log(res)
						if (res.code == 200) {
							uni.setStorageSync('loginTokenKey', res.result.accessToken)
							getshoplist()
						} else {
							uni.showToast({
								icon: "none",
								title: res.msg
							})
						}
					})
				},
				fail: function(err) {
					
				}
			})
		}
	
	}
	//关注门店
	const soreidadd=()=>{
		storeconcern({storeId:headtals.id}).then(res=>{
			if(res.code==200){
				uni.showToast({
					icon:'none',
					title:res.msg
				})
				setTimeout(()=>{
					uni.switchTab({
						url: "/pages/index/index"
					})
				},500)
			}else{
				uni.showToast({
					icon:'none',
					title:res.msg
				})
			}
		})
	}
	//商家列表
	const bulisslist = reactive({
		list: []
	})
	const isguanzhu=ref(true)
	const getshoplist = () => {
		soreidadd()
		// storestores({
		// }).then(res => {
		// 	if (res.code == 200 && res.result.data.length>0) {
		// 		bulisslist.list = res.result.data
		// 		res.result.data.forEach(item=>{
		// 			if(item.id==headtals.id){
		// 				isguanzhu.value=false
		// 			}
		// 		})
		// 		setTimeout(()=>{
		// 		   	if(isguanzhu.value){
		// 			  	soreidadd()
		// 			}else{
		// 				uni.showToast({
		// 					icon:'none',
		// 					title:"您已关注该门店"
		// 				})
		// 			}
		// 		},500)
		// 	}
		// })
	}
</script>

<style scoped lang="scss">
	.nologin {
		width: 100%;
		display: flex;
		height: calc(100vh - 200rpx);
		align-items: center;
		justify-content: center;
		flex-direction: column;

		.nologinmsg {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #595968;
			line-height: 35rpx;
			padding-top: 62rpx;
		}

		.tologin {
			width: 412rpx;
			height: 98rpx;
			background: #FE861C;
			border-radius: 20rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 98rpx;
			text-align: center;
		}
	}
	.onejianlogin {
		margin-top: 40rpx;
		width: 566rpx;
		height: 98rpx;
		background: #FE861C;
		line-height: 98rpx;
		color: #fff;
		border-radius: 20rpx;
		text-align: center;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>